﻿
using Xacml.Core.Interfaces;
using Xacml.Core.Runtime;

namespace Xacml.Core.Runtime.Functions
{
  public abstract class BaseBag : FunctionBase, ITypeSpecificFunction
  {
    public abstract IDataType DataType { get; }

    public override IDataType Returns
    {
      get
      {
        return (IDataType) DataTypeDescriptor.Bag;
      }
    }

    public override bool VarArgs
    {
      get
      {
        return true;
      }
    }

    public override IDataType[] Arguments
    {
      get
      {
        return new IDataType[1]
        {
          this.DataType
        };
      }
    }

    public override EvaluationValue Evaluate(EvaluationContext context, params IFunctionParameter[] args)
    {
      IDataType dataType = this.DataType;
      BagValue bagValue = new BagValue(dataType);
      for (int parNo = 0; parNo < args.Length; ++parNo)
        bagValue.Add(args[parNo].GetTypedValue(dataType, parNo));
      return new EvaluationValue((object) bagValue, dataType);
    }
  }
}
